<?
if(isset($_GET['method']))
{
	$method = $_GET['method'];
	if($method=="del"){
		$sListId="";
		if(isset($_POST["chon"]))$sListId=$_POST["chon"];
		$sql="delete from ".$prefix."sanpham_comment where cm_id in('".str_replace(",","','",$sListId)."')";
		mysql_query($sql);
		Redirect("Bạn đã xoá thành công","?mod=product.listcomment");
	}
	else if($method=="delete"){
		$sListId=$_GET["id"];
		$sql="delete from ".$prefix."sanpham_comment where cm_id=$sListId";
		mysql_query($sql);
		Redirect("Bạn đã xoá thành công","?mod=product.listcomment");
	}
}
	$strSQL = "select * from ".$prefix."sanpham_comment WHERE 1";
	
	if(isset($_GET['t_id']) && ($_GET['t_id'] != "") ){
		$t_id = intval($_GET['t_id']);
		$strSQL .= " AND cm_sanpham_id = '".$t_id."'";
	}
	
	if(isset($_GET['u_id']) && ($_GET['u_id'] != "") ){
		$u_id = intval($_GET['u_id']);
		$strSQL .= " AND cm_nguoidung = '".$u_id."'";
	}
	///////Paging
	
	$pp=10; 
	$parr=array();
	$parr=paging($strSQL,$pp);
	$page=$parr[0];
	$limitvalue=$parr[1];
	$numofpages=$parr[2];
	$strSQL .= " order by cm_date DESC";
	$strSQL .=" LIMIT $limitvalue, $pp";
	$rs = mysql_query($strSQL) or die('Not query');
	$i=0;
	$isexits=false;
	
	if(mysql_num_rows($rs)) $isexits=true;
?>
<script language="javascript">
	function funSearch(){
		var a = document.getElementById('t_id').value;
		var b = document.getElementById('u_id').value;
		window.location = '?mod=product.listcomment&t_id=' + a + '&u_id=' + b;
	}
</script>
<div class="newsList-path"></div>
<div style="border:1px dotted #FFCC00; padding:10px;">
	<div>Tìm theo ID sản phẩm : &nbsp;&nbsp;<input type="text" name="t_id" id="t_id" size="15"></div>
	<br />
	<div>Tìm theo ID người dùng : <input type="text" name="u_id" id="u_id" size="15"></div>
	<div style="padding-left:120px; padding-top:5px;"><input type="submit" name="submit" value="Tìm" onclick="funSearch();"/></div>
</div>
	<br />

	<div style="margin-bottom:5px; font-size:14px;">
	<?
	?>
	 Có <?=$db->num_rows($rs)?> commnet được tìm thấy </div>
	<form name="frmListSp" method="post" action="?mod=product.listcomment&method=del" onSubmit="return checkInput(this,'Bạn hãy chọn ít nhất một giá trị','Bạn chắc chắn muốn xoá không');">
	<input type="hidden" name="chon" />
	<table width="100%" border="1" bordercolor="#B2DAEE" cellpadding="4">
		<tr class="newsList-content-head">
		<td width="4%" class="newsList-content-view"><input type="checkbox" name="chkall" value="0" <? if($isexits) echo "onClick=\"docheck(thisform,0);\""?>></td>
			<td width="13%" class="newsList-content-title">Người gửi</td>

		  <td width="24%" class="newsList-content-view"><div align="center">Sản phẩm</div></td>
		  <td width="38%" class="newsList-content-view"><div align="center">Nội dung </div></td>
		  <td width="13%" class="newsList-content-view"><div align="center">Ngày gửi</div></td>
			<td width="8%" class="newsList-content-position">Tùy chọn</td>
		</tr>
				<?
				while($rows = mysql_fetch_array($rs))
				{
					$i++;
					$cm_id = $rows['cm_id'];
					$cm_nguoidung = $rows['cm_nguoidung'];
					$cm_sanpham_id = $rows['cm_sanpham_id'];
					$cm_content = $rows['cm_content'];
					$cm_date = $rows['cm_date'];
				?>				
		<tr onmouseover="thisbgColor='#FEF2CB';" onmouseout="thisbgColor='#FFFFFF';" class="newsList-content-list" <? if($i%2==0) echo "bgcolor='#f2fff2'";?>>
			<td class="newsList-content-title"><input type="checkbox" name="Xoa" value="<?=$cm_id?>" onClick="docheckone(thisform);"></td>
			<td class="newsList-content-title">
            	<table cellpadding="0" cellspacing="0" width="100%">
                <tr>
					<td>
						<a class="newsList-link newsList-name" href="">
						<b><?=tenNguoiDung($cm_nguoidung);?></b></a>					</td>
                                </table>
		  </td>
			<td class="newsList-content-view"><div align="left"><?=getSanPham($cm_sanpham_id);?></div></td>
			<td class="newsList-content-view"><div align="left"><?=substr($cm_content,0,150);?></div></td>
			<td class="newsList-content-view"><div align="center"><?=format_date($cm_date);?></div></td>
			<td class="newsList-content-position">
				<a href="?mod=product.listcomment&amp;method=delete&amp;id=<?=$cm_id?>" class="menu" onclick="return confirm('Bạn có chắc chắn muốn xóa không?')"><img src="images/delete_ongif" border="0" /></a></td>
        </tr>
		<? }?>
	<tr>
   <td colspan="8" align="center">
   <input type="submit" name="submit" value="   Xoá   " class="Button">
   <input type="reset" value="Làm lại" class="Button">
   </td>
   </tr>
</table></form>
	<div class="newsList-pagging">
	<div class="raovat-paging-bound">
	<span style="padding:5px;">
	<p align="center" class="font">
			<?php echo page_div( "?mod=product.listcomment&p=%d_pg", "10", ceil ( $numofpages ), $page ); ?>
	</p>
	</span>
	</div>
	</div>
	<div class="newsList-button-back"><a href="javascript: historyback()">[Quay lại]</a></div>